
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[DeleteQuestionnaireItemDependencies]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[DeleteQuestionnaireItemDependencies]
GO

CREATE PROCEDURE [dbo].[DeleteQuestionnaireItemDependencies]  (
@itemId	INTEGER = 0
)

AS

BEGIN
	DECLARE @itemName VARCHAR(30)
	DECLARE @versionId INT

	SELECT @itemName= ItemName, @versionId = VersionId FROM QuestionnaireItem where id = @itemId

	Update QuestionnaireItem Set Parentname = null, parentvalue= null where VersionId = @versionId and parentname = @itemName
	IF @@ERROR <> 0
	BEGIN
		RAISERROR('Unable to delete Questionnaire Item Dependencies', 16, 1)
		RETURN
	END
		
		
END
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

 